package com.inqbarna.tablefixheaders.adapters;

import ohos.data.rdb.DataObservable;
import ohos.data.rdb.DataObserver;

/**
 * Common base class of common implementation for an {@link TableAdapter} that
 * can be used in {@link com.inqbarna.tablefixheaders.TableFixHeaders}.
 *
 * @author Brais Gabín (InQBarna)
 */
public abstract class BaseTableAdapter implements TableAdapter {

    private final DataObservable mDataSetObservable = new DataObservable();

    @Override
    public void registerDataSetObserver(DataObserver observer) {
        mDataSetObservable.add(observer);
    }

    @Override
    public void unregisterDataSetObserver(DataObserver observer) {
        mDataSetObservable.add(observer);
    }

    /**
     * Notifies the attached observers that the underlying data has been changed
     * and any View reflecting the data set should refresh itself.
     */
    public void notifyDataSetChanged() {
        mDataSetObservable.notifyObservers();
    }

    /**
     * Notifies the attached observers that the underlying data is no longer
     * valid or available. Once invoked this adapter is no longer valid and
     * should not report further data set changes.
     */
    public void notifyDataSetInvalidated() {
        mDataSetObservable.removeAll(); //fixme check equivalent for notifyInvalidated()
    }
}
